package cn.player.tools;

import android.app.KeyguardManager;
import android.content.Context;

public class KeyGuardLocker {
	private static KeyGuardLocker mInstance = null;
	private final String TAG = "KeyGuardLocker";
	private KeyguardManager.KeyguardLock mKeyguardLock = null;
	private KeyguardManager mKeyguardManager;

	private KeyGuardLocker(Context paramContext) {
		KeyguardManager localKeyguardManager = (KeyguardManager) paramContext
				.getSystemService(Context.KEYGUARD_SERVICE);
		this.mKeyguardManager = localKeyguardManager;
	}
	public static KeyGuardLocker getInstance(Context paramContext) {
		if (mInstance == null) {
			Context localContext = paramContext.getApplicationContext();
			mInstance = new KeyGuardLocker(localContext);
		}
		return mInstance;
	}

	public void disableKeyGuard() {
		if (this.mKeyguardLock == null) {
			return;
		}
		this.mKeyguardLock.disableKeyguard();
	}

	public void getNewKeyGuard() {
		if (this.mKeyguardLock != null) {
			releaseKeyGuard();
		}
		KeyguardManager.KeyguardLock localKeyguardLock = this.mKeyguardManager
				.newKeyguardLock("KeyGuardLocker");
		this.mKeyguardLock = localKeyguardLock;
	}

	public void reenableKeyGuard() {
		if (this.mKeyguardLock == null) {
			return;
		}
		this.mKeyguardLock.reenableKeyguard();
		this.mKeyguardLock = null;
	}

	public void releaseKeyGuard() {
		if (this.mKeyguardLock == null) {
			return;
		}
		this.mKeyguardLock.reenableKeyguard();
	}
}
